fix(phpcs): refactor environment variable handling in commands#135
Merged
fix(phpcs): refactor environment variable handling in commands#135
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors environment variable handling by consolidating duplicated code from three child command classes (BuildCommand, CleanCommand, CompatibilityCheckCommand) into the AbstractCommand base class. The changes aim to improve code maintainability, enhance security through better sanitization, and eliminate code duplication.
Changes:
- Centralized environment variable management (get, set, sanitize, cache) in
AbstractCommandwith enhanced validation and sanitization routines - Removed duplicated environment variable code from
BuildCommand,CleanCommand, andCompatibilityCheckCommand - Improved code formatting for multi-line method signatures and sprintf calls in
BuildCommandandCleanCommand
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/Console/Command/AbstractCommand.php | Added comprehensive environment variable handling methods with sanitization; changed visibility of prompt-related methods to protected for child class access |
| src/Console/Command/Theme/BuildCommand.php | Removed duplicated environment variable code; improved formatting of multi-line sprintf calls |
| src/Console/Command/Theme/CleanCommand.php | Removed duplicated environment variable code; reformatted displayMultiThemeSummary method signature |
| src/Console/Command/Hyva/CompatibilityCheckCommand.php | Removed duplicated environment variable and prompt management code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors environment variable handling across several console command classes to centralize and secure the logic in the
AbstractCommandbase class. The main improvements include removing duplicated environment management code from child classes and enhancing the safety and consistency of environment variable access, sanitization, and mutation. Additionally, some minor formatting changes improve code readability.Centralization and Security of Environment Variable Handling:
Refactored environment variable logic to
AbstractCommand:AbstractCommand, with improved validation and sanitization routines. Methods such asgetEnvVar,setEnvVar, and related helpers are now only present and maintained in the base class. (src/Console/Command/AbstractCommand.php[1] [2] [3] [4]setPromptEnvironment,resetPromptEnvironment) and detecting interactive terminals (isInteractiveTerminal) are nowprotectedin the base class for reuse. (src/Console/Command/AbstractCommand.php[1] [2] [3]Removed redundant code from child command classes:
BuildCommand,CleanCommand, andCompatibilityCheckCommand, relying on the base class implementation instead. (src/Console/Command/Theme/BuildCommand.php[1] [2];src/Console/Command/Theme/CleanCommand.php[3];src/Console/Command/Hyva/CompatibilityCheckCommand.php[4] [5]Code Quality and Readability Improvements:
src/Console/Command/Theme/BuildCommand.php[1] [2]These changes make environment variable management more secure and maintainable, reduce code duplication, and improve the clarity of command output.